/*
 * Copyright (C) 2010 LianHaidong <lianhaidong@gmail.com>
 */

#include "utils/mem_dbg.h"

static LIST_HEAD(mem_list);

void *mem_alloc(int size, char *file, int line)
{
	struct mem_entry *me;
	struct mem_dbg_pos *pos;

	me = malloc(sizeof(*me) + size);
	if (!me)
		return NULL;
	INIT_LIST_HEAD(me->pos_list);	
	MEM_ENTRY_SET_MAGIC(me);
	me->count = 1;
	list_add(&me->entry, &mem_list);
	pos = mem_dbg_pos_create(file, line);
	if (!pos) {
		free(me);
		return NULL;
	}
	list_add(&pos->entry, &pos->pos_list);
	me->count ++;
	return me;
}

